<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends CommonController{
    public function index(){
        $this->display();
    }
    public function welcome()
    {
    	
    	if(S('welcomeData')){
    		var_dump(888);
    		$data = S('welcomeData');
    	}else{
    		var_dump(777);
    		$data = $this->conutData();
    		S('welcomeData',$data ,3600);
    	}

    	$this->assign('data',$data);
    	$this->display();
    }

    public function conutData()
    {
    	$str = date('y-m-d');

    	$time = strtotime(date('y-m-d'));

    	$yesterday = strtotime("-1 days",$time);

    	$week = strtotime("-7 days",$time);

    	$mooth = strtotime("-30 days",$time);

    	$data = array();


    	$sql = "select count(id) cn from question";
    	$res = M()->query($sql);
    	$data['总数'][] = M()->query($sql)[0]['cn'];


    	$sql = "select count(id) cn from answer";
    	$res = M()->query($sql);
    	$data['总数'][] = M()->query($sql)[0]['cn'];


    	$sql = "select count(id) cn from user";
    	$res = M()->query($sql);
    	$data['总数'][] = M()->query($sql)[0]['cn'];





    	$sql = "select count(id) cn from question where create_time>'{$time}'";
    	$res = M()->query($sql);
    	$data['今天'][] = M()->query($sql)[0]['cn'];


    	$sql = "select count(id) cn from answer where create_time>'{$time}'";
    	$res = M()->query($sql);
    	$data['今天'][] = M()->query($sql)[0]['cn'];

    	$sql = "select count(id) cn from user where create_time>'{$time}'";
    	$res = M()->query($sql);
    	$data['今天'][] = M()->query($sql)[0]['cn'];



    	$sql = "select count(id) cn from question where create_time>'{$yesterday}' and create_time<'{$time}'";
    	$res = M()->query($sql);
    	$data['昨天'][] = M()->query($sql)[0]['cn'];

    	$sql = "select count(id) cn from answer where create_time>'{$yesterday}' and create_time<'{$time}'";
    	$res = M()->query($sql);
    	$data['昨天'][] = M()->query($sql)[0]['cn'];

    	$sql = "select count(id) cn from user where create_time>'{$yesterday}' and create_time<'{$time}'";
    	$res = M()->query($sql);
    	$data['昨天'][] = M()->query($sql)[0]['cn'];




    	$sql = "select count(id) cn from question where create_time>'{$week}'";
    	$res = M()->query($sql);
    	$data['本周'][] = M()->query($sql)[0]['cn'];

    	$sql = "select count(id) cn from answer where create_time>'{$week}'";
    	$res = M()->query($sql);
    	$data['本周'][] = M()->query($sql)[0]['cn'];

    	$sql = "select count(id) cn from user where create_time>'{$week}'";
    	$res = M()->query($sql);
    	$data['本周'][] = M()->query($sql)[0]['cn'];


    	$sql = "select count(id) cn from question where create_time>'{$mooth}'";

    	$res = M()->query($sql);

    	$data['本月'][] = M()->query($sql)[0]['cn'];

    	$sql = "select count(id) cn from answer where create_time>'{$mooth}'";

    	$res = M()->query($sql);

    	$data['本月'][] = M()->query($sql)[0]['cn'];

    	$sql = "select count(id) cn from user where create_time>'{$mooth}'";

    	$res = M()->query($sql);

    	$data['本月'][] = M()->query($sql)[0]['cn'];

    	return $data;
    }

    public function getData()
    {
    	$arr = array(
    		array(
    			'value'=>300,
    			'name'=>'北京'
    			),
    		array(
    			'value'=>400,
    			'name'=>'广州'
    			),
    		array(
    			'value'=>300,
    			'name'=>'深圳'
    			),
    		array(
    			'value'=>450,
    			'name'=>'上海'
    			)
    		);

    	echo json_encode($arr);
    }
}